
program newton_root
    implicit none
    real f,x,f1,accuracy,x1
    integer n
    f(x)=x**3-2*x**2+x-1
    f1(x)=3*x**2-4*x+1
    print *, 'please input the accuracy you want, such as 0.00001'
    read(*, *) accuracy
    !f(x)=x**3-2*x**2+x-1
    !f(x)'=3*x**2-4*x+1
    !root near 1.5

    n=1
    print *,'input x, near a root you already know'
    read (*, *) x !x=1.5

10 x1=x
     x=x1-(f(x1)/f1(x1))
     print *, 'n=',n,'x1=',x1,'x=',x
     n=n+1
     if (abs(x-x1) .GT. accuracy) goto 10

    print *, 'times=',n,'root=',x1

end program

